//---------------------------------------------------------------------------

#include "vcl_stl.h"
#pragma hdrstop

#include "h_progressbar.h"

//---------------------------------------------------------------------------

void __fastcall HProgressBar::SetRate(int ARate)
{
   int MinRate = ARate < FRate ? ARate : FRate;
   
   FRate = ARate;

   if ( Parent != NULL && Parent->HandleAllocated() )
   {
      TRect Rect(Left + ( Width - 6 ) * MinRate / 100 + 3, Top + 5,
         Left + Width - 3 , Top + Height - 5);
      InvalidateRect(Parent->Handle, &Rect, false);
   }
}

void __fastcall HProgressBar::SetShowFlag(bool AShowFlag)
{
   if ( FShowFlag != AShowFlag )
   {
      Invalidate();
   }

   FShowFlag = AShowFlag;
}

void __fastcall HProgressBar::Paint(void)
{
   if ( FShowFlag )
   {
      Canvas->Brush->Color = clBlack;
      Canvas->FrameRect(TRect(3, 5, Width - 3, Height - 5));
      Canvas->Brush->Color = clGreen;
      Canvas->FillRect(TRect(3, 5, ( Width - 6 ) * FRate / 100 + 3, Height - 5));
   }
}

#pragma package(smart_init)
